package moxl.xpath;

import java.util.HashMap;
import java.util.Map;

import moxl.xpath.parser.states.step.Function;

public class FunctionMap
{
	private final Map<String, Function> functions = new HashMap<String, Function>();

	public void add(Function function)
	{
		functions.put(function.getName(), function);
	}

	public Function getFunction(String name)
	{
		if (name == null)
		{
			throw new IllegalArgumentException("function name cannot be null");
		}
		Function result = functions.get(name);
		if (result == null)
		{
			throw new IllegalStateException("Function not recognized: " + name);
		}
		return result;
	}

}
